<?php 
$log_config = parse_ini_file('./log.ini',true);
$table_config = parse_ini_file('./table.ini',true);
 
$req = $_POST;
$game_id = $req['gid'];
$sid = $req['sid'];

$calc_sign = calc_sign($req,$log_config['log_key'][$game_id]); 
if($req['sign']!=$calc_sign){
	//throw new Exception('sign error');
} 
//参数验证 省略

// $log_dir = "/data/log/%s/%s/%s/%s/";
$log_dir = $log_config['log']['path']."/%s/%s/%s/%s/";
$log_dir = sprintf($log_dir,$log_config['game'][$game_id],$log_config['platform'][$game_id],$sid,date("Y/m/d"));

$log_file = $log_dir.$req['api'].date("H").".txt";
if(!is_dir($log_dir)){
	mkdir($log_dir,0755,true);
}

/***
	log_time
	api
	gid
	sid
	oldsid
	user_id
	role_id
	part_id
	time
**/

$log_common = "%s %s %s,%s,%s,%s,%s,%s,%s";
$log_common = sprintf($log_common,$req['log_time'],$req['api'],$req['gid'],$req['sid'],$req['oldsid'],$req['user_id'],$req['role_id'],$req['part_id'],$req['time']);
$table_key = array_keys($table_config[$req['api']]);
$log_data = array();
foreach($table_key as $k){
	$log_data[] = $req[$k];
}
$log_data_str = $log_common.','.implode(',',$log_data); 
error_log($log_data_str.PHP_EOL,3,$log_file);

///data/log/tianyu/menle/s1/2018/03/29/

function calc_sign(array $params,$signKey)
{
    //自然排序
    ksort($params);
     //组装数据
    $string = '';
    foreach($params as $key => $value){
        $string .= $key . '=' . $value . '&';
    }
    //md5
    return md5($string . $signKey);
}

	